#include <iostream>
#include <sstream>
using namespace std;

#include <purewell/system.hpp>
#include <purewell/code/hexa.hpp>
using namespace purewell;

void
test1(char c)
{
	char o[2];
	cout << c << " = ";
	gPWHexa.encode(o, c, true);
	cout.write(o,2)  << " = ";
	cout << gPWHexa.decode(o) << endl;
}

int
main(int argc, char* argv[])
{
	gPWSystem.setLibraryLogStream(&cerr);

	string src("Hello, world! O'relly\nGood day~");

	cout << "Source: <<";
	cout.write(src.c_str(), src.size()+1);
	cout << ">>" << endl << endl;

	char ebuf[src.size()*2+1];
	size_t ebuflen(gPWHexa.encode(ebuf, src.c_str(), src.size()+1));
	ebuf[ebuflen+1] = 0x00;

	cout << "Encode: <<";
	cout.write(ebuf, ebuflen);
	cout << ">>" << endl << endl;

	char dbuf[ebuflen+1];
	size_t dbuflen(gPWHexa.decode(dbuf, ebuf, ebuflen));
	dbuf[dbuflen+1] = 0x00;

	cout << "Decode: <<";
	cout.write(dbuf, dbuflen);
	cout << ">>" << endl << endl;

	istringstream is(src);
	cout << "Encode: <<";
	gPWHexa.encode(cout, is);
	cout << ">>" << endl << endl;

	string ebuf2(ebuf, ebuflen);
	istringstream is2(ebuf2);
	cout << "Decode: <<";
	gPWHexa.decode(cout, is2);
	cout << ">>" << endl << endl;

	test1('a');
	test1('A');
	test1(',');
}

